home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / sound / players / naudio.lzh / naudio / examples / s_player.c < prev   
C/C++ Source or Header  |  1993-11-23  |  4KB  |  154 lines

  1. /* ----------------------------------------------------------
  2.    Hello,
  3.       this is a little demo program to show you how to
  4.       play samples with the NAUDIO library.
  5.       This is a little .TTP program that plays the file
  6.       given on the command line.
  7.  
  8.       You can find a demo sample in NAUDIO\SAMPLES.
  9.                                 ("ausgebufft und abgelascht")
  10.    --------------------------------------------------------- */
  11. #include <naudio\naudio.h>
  12. #include <stdlib.h>
  13. #include <tos.h>
  14. #include <errno.h>
  15. #include <stdio.h>
  16. #include <ctype.h>
  17.  
  18. #define FRQ          11000
  19. #define DEF_ENGINE   PSG_ENGINE
  20.  
  21.  
  22.  
  23. main( argc, argv)
  24. char  *argv[];
  25. {
  26.    int         i = 0;
  27.    n_sample    *q;
  28.    channel     *p;
  29.    lword       foo;
  30.    static long efrq = FRQ,
  31.                frq = 0L;
  32.    static int  type = DEF_ENGINE;
  33.    static int  loop = 0;
  34.    static char flag = 0;
  35.  
  36.    naudio_init();                            /* init library */
  37.    naudio_all();                             /* load in all output devices */
  38.  
  39.    while( ++i < argc)
  40.    {
  41.       if( *argv[i] == '-')
  42.       {
  43.          if( flag)
  44.             goto usage;
  45.  
  46.          switch( tolower( argv[i][1]))
  47.          {
  48.             case 'e' :
  49.                if( ++i >= argc)
  50.                   goto usage;
  51.                foo = atol( argv[ i]);
  52.                if( foo)
  53.                   efrq = foo;
  54.                else
  55.                   goto usage;
  56.                break;
  57.  
  58.             case 'f' :
  59.                if( ++i >= argc)
  60.                   goto usage;
  61.                frq = atol( argv[ i]);
  62.                break;
  63.  
  64.             case 'l' :
  65.                loop = ! loop;
  66.                break;
  67.  
  68.             case 'd' :
  69.                if( ++i >= argc)
  70.                   goto usage;
  71.                type = (int) atol( argv[ i]);
  72.                break;
  73.  
  74.             default  :
  75.                goto usage;
  76.          }
  77.       }
  78.       else
  79.       {
  80.          if( ! flag)
  81.          {
  82.                         /* init engine for enginefrequency 'efrq' and
  83.                            output device 'type' */
  84.             if( ! nsample_engine( efrq, type))
  85.             {
  86.                perror( "Invalid device specification");
  87.                return( 1);
  88.             }
  89.             flag = 1;
  90.          }
  91.  
  92.                         /* now load sample into dynamic memory */
  93.          if( ! (q = nsample_load( argv[ i])))
  94.          {
  95.             perror( "Load of sample failed: ");
  96.             naudio_done();
  97.             return( 1);
  98.          }
  99.                         /* want to loop the sample ? Then set the
  100.                            repeat length to length of the sample */
  101.          if( loop)
  102.             q->replen = q->len;
  103.  
  104.                         /* prepare sample for playing, by putting it
  105.                            on a channel (not audible yet!) */
  106.          if( ! (p = nsample_play( q, frq, NAUDIO_MAX_VOL, 1)))
  107.          {
  108.             fprintf( stderr, "No more samples can be played\n");
  109.             continue;
  110.          }
  111.  
  112.                         /* now start the soundsystem. Let there be NOIZE! */
  113.          if( naudio_start( 0))
  114.          {
  115.             fprintf( stderr, "Soundsystem is locked\n");
  116.             naudio_done();
  117.             return( 1);
  118.          }
  119.  
  120.                         /* till we tire of it, or the sample ends */
  121.          while( ! Bconstat( 2) && p->play);
  122.  
  123.                         /* mmh, still playing ?? */
  124.          if( p->play)
  125.          {
  126.             channel_stop( p);    /* and stop the channel    */
  127.             Bconin( 2);          /* grab key from keyboard  */
  128.          }
  129.          naudio_halt();          /* turn off the engine     */
  130.          channel_delete( p);     /* free that channel       */
  131.          nsample_free( q);       /* and the loaded sample   */
  132.       }
  133.    }
  134.  
  135.    if( flag)            /* did we do anything then leave normally */
  136.    {
  137.       naudio_done();    /* ALWAYS CALL THIS BEFORE LEAVING!! */
  138.       return( 0);
  139.    }
  140.  
  141. usage:
  142.    naudio_done();
  143.    fprintf( stderr,
  144. "Usage: s_player [flags] <samplefile>+\n\
  145. \t-e <engine-frequency> from 48Hz to 60000Hz (def: %dHz)\n\
  146. \t-f <sample-frequency> (0L default, -1L use engine-frq)\n\
  147. \t-d <n>, 0: slow PSG,   1: fast PSG    2:PP (StarSampler)\n\
  148. \t        3: fast STE    4: good STE\n\
  149. \t        7: fast FALCON 8: good FALCON 9:fastest FALCON(!)\n\
  150. \t-l loop sample\n\
  151. \t-v output conversational data\n", FRQ);
  152.    return( 1);
  153. }
  154.